<html>
<head><meta charset="utf-8"><title>Why does rustc use `ref` instead of match ergonomics? · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html">Why does rustc use `ref` instead of match ergonomics?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217572961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217572961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217572961">(Nov 22 2020 at 22:14)</a>:</h4>
<p>Is it just because there's a lot of existing code using <code>ref</code>? Or is it the preferred style?</p>



<a name="217573273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217573273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217573273">(Nov 22 2020 at 22:20)</a>:</h4>
<p>My guess is that most cases are just old enough to predate match ergnomics, I don't think it's the preferred style.</p>



<a name="217585817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217585817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217585817">(Nov 23 2020 at 03:26)</a>:</h4>
<p>And cause there's no <code>rustfix</code> for it.</p>



<a name="217868416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217868416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217868416">(Nov 25 2020 at 10:42)</a>:</h4>
<p>Also a lot of things are Copy, so using match ergonomics forces you to deref a bunch</p>



<a name="217868505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217868505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217868505">(Nov 25 2020 at 10:44)</a>:</h4>
<p>i fairly strongly prefer <code>match *x { Type(a, ref x) =&gt; func(a, x) }</code> over <code>match x { Type(a, x) =&gt; func(*a, x) }</code></p>



<a name="217928404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217928404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217928404">(Nov 25 2020 at 19:27)</a>:</h4>
<p>I never used <code>match *x {}</code> before working on rustc because I rarely had Copy members. It feels wrong to me because <code>*x</code> isn't a real value; among other things it means I can't tuple it with something else if I want to match two things at once. That made me always prefer match ergonomics. Frankly I'd love some kind of auto-deref of Copy types so that I can keep match ergonomics but I don't have to deref manually. Or at least allow patterns like <code>match x { Type(&amp;a, x) =&gt; func(a, x) }</code></p>



<a name="217944020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944020">(Nov 25 2020 at 21:57)</a>:</h4>
<p><span class="user-mention" data-user-id="245339">@Nadrieril</span> You <em>can</em> write patterns like <code>&amp;a</code> to match a <code>&amp;Foo</code> and get a <code>Foo</code>.</p>



<a name="217944067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944067">(Nov 25 2020 at 21:57)</a>:</h4>
<p>Yes but not as a subpattern, right?</p>



<a name="217944123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944123">(Nov 25 2020 at 21:58)</a>:</h4>
<p>Testing...</p>



<a name="217944188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944188">(Nov 25 2020 at 21:59)</a>:</h4>
<p>As in, say <code>x: &amp;Option&lt;(u64, Foo)&gt;</code>, I would like <code>match x { Some((&amp;i, foo)) =&gt; ... }</code></p>



<a name="217944194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944194">(Nov 25 2020 at 21:59)</a>:</h4>
<p>Just confirmed that you can. This works:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">vec</span><span class="o">!</span><span class="p">[</span><span class="mi">0</span><span class="k">u32</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">v</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">v</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="p">(</span><span class="o">&amp;</span><span class="n">value</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">value2</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">show_me_the_type</span>: <span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">value</span><span class="p">;</span><span class="w"></span>
<span class="w">            </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">value2</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">};</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217944242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944242">(Nov 25 2020 at 21:59)</a>:</h4>
<p>The <code>&amp;</code> in my example isn't because there's an actual ref in the corresponding type there. Rather, the ref only appears because of match ergonomics</p>



<a name="217944246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944246">(Nov 25 2020 at 21:59)</a>:</h4>
<p><em>oh</em>. You want a subpattern where the <code>&amp;</code> isn't where the reference is.</p>



<a name="217944312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944312">(Nov 25 2020 at 22:00)</a>:</h4>
<p>Yeah, to avoid needing to dereference when the binding is copy and I'm using ergonomics</p>



<a name="217944324"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944324" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944324">(Nov 25 2020 at 22:00)</a>:</h4>
<p>There's an issue somewhere for this</p>



<a name="217944404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944404">(Nov 25 2020 at 22:01)</a>:</h4>
<p>Can't help you there; the compile error that produces is exactly what I hope it <em>keeps</em> producing.</p>



<a name="217944420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944420">(Nov 25 2020 at 22:01)</a>:</h4>
<p>Oh :(</p>



<a name="217944436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944436">(Nov 25 2020 at 22:01)</a>:</h4>
<p>(That's not the only position on the matter, though.)</p>



<a name="217944492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944492">(Nov 25 2020 at 22:02)</a>:</h4>
<p>Subject of much debate, and I'm not looking to reopen it here; I just misunderstood your original question.</p>



<a name="217944521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944521">(Nov 25 2020 at 22:02)</a>:</h4>
<p>Oh yeah, got sidetracked sry.</p>



<a name="217944717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217944717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217944717">(Nov 25 2020 at 22:05)</a>:</h4>
<p>(Found the issue, if anyone is curious: <a href="https://github.com/rust-lang/rust/issues/64586">https://github.com/rust-lang/rust/issues/64586</a>)</p>



<a name="217956049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217956049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217956049">(Nov 26 2020 at 00:58)</a>:</h4>
<p>I use <code>ref</code> because I frankly still don't understand match ergonomics...</p>



<a name="217959286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217959286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217959286">(Nov 26 2020 at 02:08)</a>:</h4>
<p>The issue <span class="user-mention" data-user-id="245339">@Nadrieril</span> linked makes it much less intuitive than it ought to be, for me.</p>



<a name="217962182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217962182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217962182">(Nov 26 2020 at 03:24)</a>:</h4>
<p>I feel somewhat strongly that instead of the "default binding mode" implementation, <code>Some(pat): &amp;Option&lt;T&gt;</code>  should just match <code>pat: &amp;T</code> so that <code>Some(&amp;x)</code> and <code>&amp;Some(x)</code> are equivalent when matching a <code>&amp;Option&lt;T&gt;</code>. This is really simple and easy to teach, but I recall in the issue about this (I don't think it's the one <span class="user-mention silent" data-user-id="245339">Nadrieril</span> found) it was pointed out that this is backward incompatible when matching <code>Some(p): &amp;&amp;Option&lt;u32&gt;</code> that <code>p</code> will currently get type <code>&amp;u32</code> and the suggested approach gives it type <code>&amp;&amp;u32</code>. I think this is something an edition boundary (and maybe a lint) can solve though.</p>



<a name="217962539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217962539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217962539">(Nov 26 2020 at 03:33)</a>:</h4>
<p>(I'm not exactly sure if this is the issue I'm thinking of but <a href="https://github.com/rust-lang/rfcs/pull/2005">https://github.com/rust-lang/rfcs/pull/2005</a> has a bunch of discussion on this point.)</p>



<a name="217962957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217962957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217962957">(Nov 26 2020 at 03:43)</a>:</h4>
<p>Hm, so match ergonomics collapse multiple refs? I think we can still allow <code>Some(&amp;p)</code> there without breaking backcompat. The collapse of nested refs will stay a source of confusion with or without this I think</p>



<a name="217962981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217962981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217962981">(Nov 26 2020 at 03:44)</a>:</h4>
<p>But I should read the discussion first</p>



<a name="217963118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217963118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217963118">(Nov 26 2020 at 03:46)</a>:</h4>
<p>No, because <code>Some(&amp;x): &amp;Option&lt;&amp;u32&gt;</code> will currently give <code>x</code> the type <code>u32</code></p>



<a name="217963129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217963129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217963129">(Nov 26 2020 at 03:47)</a>:</h4>
<p>because the changed default binding mode isn't actually a ref, you can't match on it</p>



<a name="217963327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Why%20does%20rustc%20use%20%60ref%60%20instead%20of%20match%20ergonomics%3F/near/217963327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Why.20does.20rustc.20use.20.60ref.60.20instead.20of.20match.20ergonomics.3F.html#217963327">(Nov 26 2020 at 03:52)</a>:</h4>
<p>I don't think it makes a whole lot of sense to have <code>Some(p): &amp;&amp;Option&lt;T&gt;</code> give <code>p</code> the type <code>&amp;&amp;T</code>; it works in the syntactic sense but there is no second pointer available so the match basically has to invent a <code>&amp;T</code> local just so it can be pointed to. I would much prefer that this be an error though, where we just tell people to use <code>&amp;Some(p)</code> instead if they want a <code>&amp;T</code> (and if they want a <code>&amp;&amp;T</code> they will have to build it themselves outside the match)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>